/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Akanksha;
/**
 *
 * @author Akanksha Chauhan
 */
public class Timer {
    
    private long startTime = 0;
    private long stopTime = 0;
    private long pauseTime = 0;
    
    private boolean running = false;
    public static enum Status { RUNNING , NOTRUNNING } ;
    public static Status status;
    
    public void start() {
        this.startTime = System.currentTimeMillis();
        this.running = true;
        status = Status.RUNNING;
    }

    
    public void stop() {
        this.stopTime = System.currentTimeMillis();
        this.running = false;
        status = Status.NOTRUNNING;
    }

    public void pause()
    {
        this.pauseTime = System.currentTimeMillis();
        this.running = false;
        status = Status.NOTRUNNING;    
    }
    public void resume()
    {
        this.startTime = this.pauseTime;
        this.running = true;
        status = Status.RUNNING;
    }
    //elaspsed time in milliseconds
    public long getElapsedTime() {
        long elapsed;
        if (running) {
             elapsed = (System.currentTimeMillis() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }
        return elapsed;
    }
    
    
    //elaspsed time in seconds
    public long getElapsedTimeSecs() {
        long elapsed;
        if (running) {
            elapsed = ((System.currentTimeMillis() - startTime) / 1000);
        }
        else {
            elapsed = ((stopTime - startTime) / 1000);
        }
        return elapsed;
    }

}
